package com.tom.web.controller;

import com.tom.doc.CourseDoc;
import com.tom.dto.SearchDto;
import com.tom.service.ICourserOnLineAndOffLineServie;
import com.tom.service.IESSearchService;
import com.tom.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/course")
public class CourseOnLineAndOffLineController {
    @Autowired
    private ICourserOnLineAndOffLineServie courserOnLineAndOffLineServie;

    @Autowired
    private IESSearchService searchService;

    /**
     * 上架
     * @param doc
     * @return
     */
    @PreAuthorize("hasAnyAuthority('course:saveCoursesss')")
    @PostMapping("/courseOnLine")
    public AjaxResult courseOnLine(@RequestBody CourseDoc doc){
        courserOnLineAndOffLineServie.courseOnLine(doc);
        return AjaxResult.me();
    }

    /**
     * 下架
     * @param doc
     * @return
     */
    @PostMapping("/courseOffLine")
    public AjaxResult courseOffLine(@RequestBody CourseDoc doc){
        courserOnLineAndOffLineServie.courseOffLine(doc);
        return AjaxResult.me();
    }

    /**
     * 门户网站的展示，从ES中查找
     * @param searchDto 接收参数的对象
     * @return
     */
    @PostMapping("/search")
    public AjaxResult getSearch(@RequestBody SearchDto searchDto){
        return AjaxResult.me().setSuccess(true).setResultObj(searchService.getSearch(searchDto));
    }
}
